import T from './台湾政治人物分类.json';

const fromEntries = (arr) => {
  for (let i = 0; i < arr.length; i++) {
    const element = arr[i];
    element.parentLevel = element.parentLevel ? `${element.parentLevel}.${i + 1}` : (i + 1);
    element.name = `${element.parentLevel} ${element.value}`
    element.type = 'category';
    if (element.children && element.children.length > 0) {
      element.children = fromEntries(element.children,)
    }
  }
  return arr;
}
Down(fromEntries([...T]))

function Down(arr) {
  // 下载保存json文件
  var eleLink = document.createElement("a");
  eleLink.download = 'xxxxxx.json';
  eleLink.style.display = "none";
  // 字符内容转变成blob地址
  var data = JSON.stringify(arr, undefined, 4);
  var blob = new Blob([data], { type: "text/json" });
  eleLink.href = URL.createObjectURL(blob);
  // 触发点击
  document.body.appendChild(eleLink);
  eleLink.click();
  // 然后移除
  document.body.removeChild(eleLink);
}